/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

#include <config.h>

#include <gtk/gtk.h>

#include <eel/eel-gtk-extensions.h>
#include <eel/eel-stock-dialogs.h>


static void
quit (GtkWidget *widget, gpointer data)
{
    gtk_main_quit ();
}

static void
info_button_clicked (GtkButton *button,
                           gpointer user_data)
{
    eel_show_info_dialog ("info dialog", "this is a info dialog", GTK_WINDOW (user_data));
}

static void
warning_button_clicked (GtkButton *button,
                           gpointer user_data)
{
    eel_show_warning_dialog ("warning dialog", "this is a warning dialog", GTK_WINDOW (user_data));
}

static void
error_button_clicked (GtkButton *button,
                           gpointer user_data)
{
    eel_show_error_dialog ("error dialog", "this is a error dialog", GTK_WINDOW (user_data));
}

static void
error_dialog_with_details_button_clicked (GtkButton *button,
                           gpointer user_data)
{
    eel_show_error_dialog_with_details ("error dialog with details", "this is a error dialog with details", "error details", GTK_WINDOW (user_data));
}

static void
yes_no_button_clicked (GtkButton *button,
                           gpointer user_data)
{
	GtkDialog *dialog;
	int response;

    dialog = eel_show_yes_no_dialog ("yes no dialog", "this is a yes no dialog", "yes", "no", GTK_WINDOW (user_data));
	response = gtk_dialog_run (dialog);
	gtk_widget_destroy (GTK_WIDGET (dialog));

    if (response == GTK_RESPONSE_CANCEL) {
        g_print ("GTK_RESPONSE_CANCEL\n");
    } else {
        g_print ("GTK_RESPONSE_YES\n");
    }
}

static gboolean
geometry_string_changed (GtkWindow *window,
                           GdkEvent  *event,
                           gpointer user_data)
{
    g_return_val_if_fail (GTK_WINDOW (window) != NULL, GDK_EVENT_PROPAGATE);
    g_print ("geometry string:%s\n", eel_gtk_window_get_geometry_string (GTK_WINDOW (window)));
    return GDK_EVENT_PROPAGATE;
}

int 
main (int argc, char* argv[])
{
    GtkWidget *window;
    GtkWidget *vbox;
    GtkWidget *button;
	char *geometry_string;

    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (quit), NULL);
    
    eel_gtk_window_set_initial_geometry_from_string (GTK_WINDOW (window), "800x500+900+400", 600, 350, FALSE);

    geometry_string = eel_gtk_window_get_geometry_string (GTK_WINDOW (window));
    g_print ("geometry string:%s\n", geometry_string);

    g_signal_connect (window, "configure-event",
                      G_CALLBACK(geometry_string_changed), window);

    vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);

    gtk_container_add (GTK_CONTAINER (window), vbox);

    button = gtk_button_new_with_label ("info dialog");

    gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 4);

    g_signal_connect (button, "clicked",
                      G_CALLBACK(info_button_clicked), window);


    button = gtk_button_new_with_label ("warning dialog");

    gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 4);

    g_signal_connect (button, "clicked",
                      G_CALLBACK(warning_button_clicked), window);


    button = gtk_button_new_with_label ("error dialog");

    gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 4);

    g_signal_connect (button, "clicked",
                      G_CALLBACK(error_button_clicked), window);

    button = gtk_button_new_with_label ("error dialog with details");

    gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 4);

    g_signal_connect (button, "clicked",
                      G_CALLBACK(error_dialog_with_details_button_clicked), window);

    button = gtk_button_new_with_label ("yes no dialog");

    gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 4);

    g_signal_connect (button, "clicked",
                      G_CALLBACK(yes_no_button_clicked), window);

    gtk_widget_show_all (window);
    
    gtk_main ();

    return 0;
}
